//
//  CategorySubVC.m
//  LazyCat
//
//  Created by linhui on 16/3/2.
//  Copyright (c) 2016年 zhanshu. All rights reserved.
//

#import "CategorySubVC.h"
#import "FeWifiManHub.h"
#import "ProductLibTableviewCell.h"//公共库cell
#import "classifyViewController.h"
#import "AFNetworking.h"
#import "ProductLibEditVC.h"
#import "MallCategoryVC.h"

#define backColor SetColor(245, 245, 249, 1)

@interface CategorySubVC ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate>
{
    UICollectionView *_collectionView;
    UITableView *_tableView;
    NSMutableArray *_dataArrayTwo;//专题数据源
    UIButton *_upBtn;//上调btn
    NSString *_picUrl;//头视图image
    NSString * _urlIndex;//起始页
    NSString *_totalCount;//总页数
    BOOL _isLoading;
    NSTimer *timer;// 定时器
    NSInteger _timestamp;//时间戳
    UIView *_backTView;
    FeWifiManHub *_loading;
    NSString *_sortTypeStr;//分类号
    UIView *_backEditView;//编辑视图
    BOOL _IsHidden;
    UIView *_bottomView;
    NSMutableArray *_selectedArr;//全选的数据
    
    NSString *_cname;
    NSString *_cid;
    UILabel *_cnameLabel;//分类名label
    UIButton *_chooseCateBtn;
    UIView *_editView;
    
    NSString *_shoujiaStr;
    NSString *_chengbenStr;
    NSString *_kucunStr;
    NSString *_pid;
}

@end

@implementation FileItem
@synthesize checked = _m_checked;
+ (FileItem*) fileItem
{
    return [[self alloc] init];
}
@end

@implementation CategorySubVC

- (void)viewDidLoad {
    [super viewDidLoad];
    _dataArrayTwo = [[NSMutableArray alloc] init];
    _urlIndex = @"1";
    _isLoading = NO;
    _IsHidden = NO;
    _shoujiaStr = @"";
    _chengbenStr = @"";
    _kucunStr = @"";
    _cid = @"";
    _pid = @"";
    _m_fileItems = [[NSMutableArray alloc] initWithCapacity:2];
    
    
    
    [self createUI];
    [self createEditView];
}
-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    MallCategoryVC *categoryVC = [AppData share].mallCategoryVC;
    typeof(self)Wself = self;
    [categoryVC setAllSelectedBlock:^(NSString * isSelected)
     {
         NSString *sort = isSelected;
         if ([sort isEqualToString:@"1"])
         {
             if (_selectedArr.count > 0) {
                 [_selectedArr removeAllObjects];
             }
             if (_m_fileItems.count > 0) {
                 [_m_fileItems removeAllObjects];
             }
             for (int idx = 0; idx < _dataArrayTwo.count; idx++)
             {
                 FileItem* fileItem = [FileItem fileItem];
                 [_m_fileItems addObject:fileItem];
             }
             [_selectedArr addObjectsFromArray:_dataArrayTwo];
             
             [_tableView setEditing:YES animated:YES];
             [self setEditing:YES animated:YES];
             NSIndexPath *indexPath;
             for (int i = 0; i < _dataArrayTwo.count; i++) {
                 indexPath = [NSIndexPath indexPathForRow:i inSection:0];
                 ProductLibTableviewCell *cell = (ProductLibTableviewCell*)[_tableView cellForRowAtIndexPath:indexPath];
                 cell.addBtn.hidden = YES;
             }
             [self refreshAddBtnState];
         }else  if ([sort isEqualToString:@"0"])
         {
             [_tableView setEditing:NO animated:YES];
             [self setEditing:NO animated:YES];
             NSIndexPath *indexPath;
             for (int i = 0; i < _selectedArr.count; i++) {
                 indexPath = [NSIndexPath indexPathForRow:i inSection:0];
                 ProductLibTableviewCell *cell = (ProductLibTableviewCell*)[_tableView cellForRowAtIndexPath:indexPath];
                 cell.addBtn.hidden = NO;
             }
             [_selectedArr removeAllObjects];
             [self refreshAddBtnState];
         }else if ([sort isEqualToString:@"2"])
#pragma mark -- 一键导入click..
         { // 一键导入
             NSMutableArray *seleArr = [[NSMutableArray alloc] init];
             [seleArr addObjectsFromArray:_selectedArr];
             for (NSInteger i = seleArr.count - 1; i >= 0; i--) {
                 NSDictionary *dic = (NSDictionary *)seleArr[i];
                 if ([[dic allKeys] containsObject:@"a"]) {
                     [seleArr removeObjectAtIndex:i];
                 }
             }
             
             NSMutableArray *arr = [NSMutableArray array];//产品信息
             NSString *prouctId;
             for (int i = 0; i < seleArr.count; i++)
             {
                 prouctId = [seleArr[i] objectForKey:@"productid"];
                 [arr addObject:prouctId];
             }
             
             
             
             NSString *kUrl;
             NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
             
             [dictionary setValue:arr forKey:@"productids"];
             NSLog(@"%@",dictionary);
             NSError *error = nil;
             //NSJSONWritingPrettyPrinted:指定生成的JSON数据应使用空格旨在使输出更加可读。如果这个选项是没有设置,最紧凑的可能生成JSON表示。
             NSData *jsonData = [NSJSONSerialization
                                 dataWithJSONObject:dictionary options:NSJSONWritingPrettyPrinted error:&error];
             if ([jsonData length] > 0 && error == nil){
                 NSLog(@"Successfully serialized the dictionary into data.");
                 //NSData转换为String
                 NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
                 NSLog(@"JSON String = %@", jsonString);
             }
             else if ([jsonData length] == 0 &&
                      error == nil){
                 NSLog(@"No data was returned after serialization.");
             }
             else if (error != nil){
                 NSLog(@"An error happened = %@", error);
             }
             //post请求
             kUrl = [NSString stringWithFormat:isRecommend,[AppData share].username,[AppData share].username];
             NSMutableDictionary *dicc = [NSMutableDictionary dictionary];
             [dicc setObject:dictionary forKey:@"data"];
             // 手机型号
             NSUserDefaults *userDefaul = [NSUserDefaults standardUserDefaults];
             NSString *iptype = [userDefaul objectForKey:@"iptype"];
             NSString *banben = [userDefaul objectForKey:@"banben"];
             NSString *temUrl = [NSString stringWithFormat:@"%@&terminal=%@&OSVersion=%@",kUrl,iptype,banben];
             // 判断是否签名
             if([temUrl rangeOfString:@"sign2"].location !=NSNotFound)//_roaldSearchText
             { // 存在
             }else{ // 不存在
                 temUrl = [NSString stringWithFormat:@"%@&sign2=%@",temUrl,[Utils md5SignStr]];
             }
             NSString *lower = [temUrl lowercaseString];
             if ([lower rangeOfString:@"username"].location !=NSNotFound) { // 存在
             }else{ // 不存在
                 temUrl = [NSString stringWithFormat:@"%@&Username=%@",temUrl,[AppData share].username];
             }
             //NSLog(@"1----------%@",temUrl);
             temUrl = [temUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
             //NSLog(@"2----------%@",temUrl);
             NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
             NSError *error1;
             LCLog(@"%@",error1);
             NSURLResponse *theResponse;
             NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:temUrl]];
             NSString *bodyString=[NSString stringWithFormat:@"data=%@",jsonString];
             [theRequest setHTTPMethod:@"POST"];
             [theRequest setHTTPBody:[bodyString dataUsingEncoding:NSUTF8StringEncoding]];
             [theRequest addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
             NSData *data = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&theResponse error:&error];
             NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
             if ([dic[@"r"] isEqualToString:@"T"]) {
                 [[MessShowView share]showWithMess:@"批量添加成功"];
                 _cid = @"";
                 
             }else {
                 [[MessShowView share]showWithMess:dic[@"m"]];
             }

         }
     }];
    
    
        //加载动画
//        _loading = [[FeWifiManHub alloc] initWithView:_collectionView withMode:FeWifiManHubModeOnlyLoader];
//        _loading.frame = CGRectMake(_loading.frame.origin.x, _loading.frame.origin.y - 104, _loading.frame.size.width, _loading.frame.size.height);
//        [self.view addSubview:_loading];
        [_loading show];
    if (_IsHidden == YES) {
        _backEditView.hidden = NO;
        _editView.frame = CGRectMake(0, ScreenHeight - 64 - 270, ScreenWidth, 270);
        _IsHidden = NO;
    }
    _upBtn.hidden = YES;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notification:) name:@"CategoryNotiF" object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(allSelectedNotification:) name:@"all_selected_BTN" object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(classifyBackNotif:) name:@"ClassifyBack" object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardDidChangeFrameNotification object:nil];//键盘高度变化通知
    
}
#pragma mark -- 键盘高度
- (void)keyboardWillChangeFrame:(NSNotification *)notification
{
    NSDictionary *info = [notification userInfo];
    CGFloat duration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
    CGRect beginKeyboardRect = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
    CGRect endKeyboardRect = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
    CGFloat yOffset = endKeyboardRect.origin.y - beginKeyboardRect.origin.y;
    CGRect inputFieldRect = _editView.frame;
    inputFieldRect.origin.y += yOffset;
    [UIView animateWithDuration:duration animations:^{
        _editView.frame = inputFieldRect;
    }];
}

#pragma mark -- 全选通知事件
- (void)allSelectedNotification:(NSNotification *)notifi {//1是编辑，0是未编辑状态
    NSString *sort = notifi.object;
    NSLog(@"%@",sort);
    //NSIndexPath * indexPP;
    if ([sort isEqualToString:@"1"]) {
        if (_selectedArr.count > 0) {
            [_selectedArr removeAllObjects];
        }
        if (_m_fileItems.count > 0) {
            [_m_fileItems removeAllObjects];
        }
        for (int idx = 0; idx < _dataArrayTwo.count; idx++)
        {
            FileItem* fileItem = [FileItem fileItem];
            [_m_fileItems addObject:fileItem];
        }
        [_selectedArr addObjectsFromArray:_dataArrayTwo];
        
        [_tableView setEditing:YES animated:YES];
        [self setEditing:YES animated:YES];
        NSIndexPath *indexPath;
        for (int i = 0; i < _dataArrayTwo.count; i++) {
            indexPath = [NSIndexPath indexPathForRow:i inSection:0];
            ProductLibTableviewCell *cell = (ProductLibTableviewCell*)[_tableView cellForRowAtIndexPath:indexPath];
            cell.addBtn.hidden = YES;
        }
        [UIView animateWithDuration:0.3 animations:^{
            _bottomView.frame = CGRectMake(0, ScreenHeight - 108 -35 - 44, ScreenWidth, 44);
        }];
    }else {
        [_tableView setEditing:NO animated:YES];
        [self setEditing:NO animated:YES];
        NSIndexPath *indexPath;
        for (int i = 0; i < _selectedArr.count; i++) {
            indexPath = [NSIndexPath indexPathForRow:i inSection:0];
            ProductLibTableviewCell *cell = (ProductLibTableviewCell*)[_tableView cellForRowAtIndexPath:indexPath];
            cell.addBtn.hidden = NO;
        }
        [UIView animateWithDuration:0.3 animations:^{
            _bottomView.frame = CGRectMake(0, ScreenHeight - 108 -35, ScreenWidth, 44);
        }];
    }
}
#pragma mark -- bottomViewBtn点击事件
- (void)bottomBtnClick:(UIButton *)sender {
    if (sender.tag == 700) {//取消全选
        NSIndexPath *indexPath;
        for (int i = 0; i < _selectedArr.count; i++) {
            indexPath = [NSIndexPath indexPathForRow:i inSection:0];
            FileItem* fileItem = [_m_fileItems objectAtIndex:indexPath.row];
            ProductLibTableviewCell *cell = (ProductLibTableviewCell*)[_tableView cellForRowAtIndexPath:indexPath];
            fileItem.checked = YES;
            [cell setChecked:fileItem.checked];
            [_tableView deselectRowAtIndexPath:indexPath animated:YES];
            if (fileItem.checked) {
                [_selectedArr replaceObjectAtIndex:indexPath.row withObject:@{@"a":@"1"}];
            }else {
                [_selectedArr replaceObjectAtIndex:indexPath.row withObject:_dataArrayTwo[indexPath.row]];
            }
        }
    }else if (sender.tag == 701){//下一步
        ProductLibEditVC *libEditVC = [[ProductLibEditVC alloc]init];
        libEditVC.dataArray = _selectedArr;
        if (_myBlock) {
            _myBlock(libEditVC);
        }
    }
}
#pragma mark -- 通知触发
- (void)notification:(NSNotification *)notifi {
    NSString *sort = notifi.object;
    _sortTypeStr = sort;
    _urlIndex = @"1";
    [self loadData];
    NSLog(@"%@",sort);
}
#pragma mark --选择分类返回通知
- (void)classifyBackNotif:(NSNotification *)notifi {
    NSString *str = notifi.object;
    NSArray *arr = [str componentsSeparatedByString:@"ym"];//arr[0]:cname, [1]cid
    NSLog(@"%@--%@",arr[0],arr[1]);
    _IsHidden = YES;
}
- (void)createUI {
    self.view.backgroundColor = [UIColor whiteColor];
    if ([_isShowSearch isEqualToString:@"YES"]) {
        [self initNav:@"搜索结果" doBack:YES];
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, ScreenWidth, ScreenHeight - 64) style:UITableViewStyleGrouped];
        UIView *lineView2 = [[UIView alloc]initWithFrame:CGRectMake(0, 63.9, ScreenWidth, 0.1)];
        lineView2.backgroundColor = SetColor(1, 1, 1, 0.2);
        [self.navBar addSubview:lineView2];
    }else {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - 108 -35) style:UITableViewStyleGrouped];
    }
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.backgroundColor = BackColor;
    _tableView.allowsMultipleSelectionDuringEditing = YES;
    _tableView.header = [MJDIYHeader headerWithRefreshingTarget:self refreshingAction:@selector(refreshData)];
    MJRefreshAutoFooter *footer = [MJRefreshAutoFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMore)];
    _tableView.footer = footer;
    [self.view addSubview:_tableView];
    _backTView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - 64)];
    _backTView.backgroundColor = BackColor;
    _backTView.hidden = YES;
    
    /**
     底部操作View
     */
    _bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, ScreenHeight - 108 -35, ScreenWidth, 44)];
    if ([_isShowSearch isEqualToString:@"YES"]) {
        _bottomView.hidden = YES;
    }
    _bottomView.backgroundColor = [UIColor whiteColor];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(10, 0, 80, 44);
    [btn setTitle:@"取消全选" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(bottomBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    btn.tag = 700;
    btn.titleLabel.font = [UIFont systemFontOfSize:14];
    [btn setTitleColor:SetColor(80, 80, 80, 1) forState:UIControlStateNormal];
    [_bottomView addSubview:btn];
    UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn2.frame = CGRectMake(ScreenWidth - 110, 0, 110, 44);
    [btn2 addTarget:self action:@selector(bottomBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    btn2.tag = 701;
    [btn2 setTitle:@"下一步" forState:UIControlStateNormal];
    btn2.backgroundColor = MainColorT;
    [btn2 setTitleColor:[UIColor whiteColor ] forState:UIControlStateNormal];
    [_bottomView addSubview:btn2];
    [self.view addSubview:_bottomView];
    
    UIView *lineView2 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 0.5)];
    lineView2.backgroundColor = SetColor(1, 1, 1, 0.2);
    [_bottomView addSubview:lineView2];
    
    UIImageView *noProImV = [[UIImageView alloc]initWithFrame:CGRectMake((ScreenWidth-49)/2, 115, 49, 49)];
    noProImV.image = [UIImage imageNamed:@"noOrder"];
    [_backTView addSubview:noProImV];
    
    UILabel *noProMess = [[UILabel alloc]initWithFrame:CGRectMake(0, 170, ScreenWidth, 20)];
    noProMess.textColor = SetColor(170, 170, 170, 1);
    noProMess.textAlignment = NSTextAlignmentCenter;
    noProMess.font = [UIFont systemFontOfSize:14];
    noProMess.text = @"暂无该相关产品";
    [_backTView addSubview:noProMess];
    [_tableView addSubview:_backTView];
    //

    //加载动画
    _loading = [[FeWifiManHub alloc] initWithView:_collectionView withMode:FeWifiManHubModeOnlyLoader];
    _loading.frame = CGRectMake(_loading.frame.origin.x, _loading.frame.origin.y, _loading.frame.size.width, _loading.frame.size.height);
    [[UIApplication sharedApplication].keyWindow addSubview:_loading];
    //[_loading show];
    self.automaticallyAdjustsScrollViewInsets=NO;
    //设置背景色，默认是黑色
//    _collectionView.backgroundColor= BackColor;
    //偏移view
    _upBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    //_upBtn.hidden = YES;
    _upBtn.frame = CGRectMake(ScreenWidth-60, ScreenHeight-208, 40, 40);
    [_upBtn setBackgroundImage:[UIImage imageNamed:@"scUPBtn"] forState:UIControlStateNormal];
    [_upBtn setBackgroundImage:[UIImage imageNamed:@"scUPBtn"] forState:UIControlStateHighlighted];
    [_upBtn addTarget:self action:@selector(upView) forControlEvents:UIControlEventTouchUpInside];
    _upBtn.layer.cornerRadius = 20.0;
    _upBtn.layer.masksToBounds = YES;
    [self.view addSubview:_upBtn];
    
    _sortTypeStr = @"";
    _selectedArr = [NSMutableArray array];
    [self loadData];
}
- (void)loadData {
//    if (kNetworkNotReachability) {
//        self.baseNetView.hidden = NO;
//        self.baseNetView.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight - 148);
//        [_collectionView addSubview:self.baseNetView];
//        [_loading dismiss];
//    }else {
//        self.baseNetView.hidden = YES;
//    }
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    NSArray *TTypeArr=[defaults objectForKey:@"PID"];
    NSString *kUrl;
    //#define ProductListGGK BaseUrl @"/WPT-OpenAPI?control=LCatBusiness&action=GetComProductByCate&categoryid=%@&pagesize=%@&pageindex=%@"
    if ([_isShowSearch isEqualToString:@"YES"]) {
        kUrl = [NSString stringWithFormat:SearchGoodsUrl,_keyWorlds];
    }else {
        kUrl = [NSString stringWithFormat:ProductListGGK,(NSString *)TTypeArr[_currentPage],@"10",_urlIndex,[AppData share].username,[AppData share].username];
    }
    
    if ([_urlIndex isEqualToString:@"1"]) {
        [_dataArrayTwo removeAllObjects];
        [_selectedArr removeAllObjects];
        [_m_fileItems removeAllObjects];
    }
    if (kNetworkNotReachability) {
        _backTView.hidden = NO;
    }else {
        _backTView.hidden = YES;
    }
    [AFNetworkHandler GETWithAFNByURL:kUrl completion:^(id result) {
        NSDictionary *dic = result;
        _totalCount = [dic objectForKey:@"totalpage"];
        NSArray *arr = [dic objectForKey:@"products"];
//        NSLog(@"arr:%@",arr);
        [_dataArrayTwo addObjectsFromArray:arr];
        for (int idx = 0; idx < _dataArrayTwo.count; idx++)
        {
            FileItem* fileItem = [FileItem fileItem];
            [_m_fileItems addObject:fileItem];
        }
        [_selectedArr addObjectsFromArray:arr];
        [_tableView.header endRefreshing];
        [_tableView.footer endRefreshing];
        _isLoading = NO;
        if (_selectedArr.count == 0) {
            _backTView.hidden = NO;
        }else {
            _backTView.hidden = YES;
        }
        if ([_isShowSearch isEqualToString:@"YES"]) {
            
        }else {
            if ([_totalCount isEqualToString:@"0"] || _totalCount == nil) {
                _backTView.hidden = NO;
            }else {
                _backTView.hidden = YES;
            }
        }
        [_loading dismiss];
        [_loading removeFromSuperview];
        [_tableView reloadData];
    }];
    
    if (kNetworkNotReachability) {
        [_loading dismiss];
        [_loading removeFromSuperview];
    }
}
#pragma mark -- 上啦加载
- (void)loadMore {
    if (_isLoading) {
        if ([_urlIndex integerValue] >= [_totalCount integerValue]) {
            [_tableView.footer noticeNoMoreData];
            [_tableView.footer endRefreshing];
        }
        return;
    }
    _isLoading = YES;
    if ([_urlIndex integerValue] >= [_totalCount integerValue]) {
        [_tableView.footer noticeNoMoreData];
        [_tableView.footer endRefreshing];
        return;
    }
    _urlIndex  = [NSString stringWithFormat:@"%ld",[_urlIndex integerValue]+1];
    [self loadData];
}
#pragma mark -- 下拉刷新
- (void)refreshData {
    if (_isLoading) {
        return;
    }
    _urlIndex = @"1";
    _isLoading = YES;
    [self loadData];
}
#pragma mark -- 上跳按钮
- (void)upView {
    [UIView animateWithDuration:0.1 animations:^{
        [_tableView setContentOffset:CGPointMake(0, 0)];
    }];
}
#pragma mark --添加按钮
- (void)addProductBtnClick:(UIButton *)sender event:(id)event{
    //取indexpath
    NSSet *touches =[event allTouches];
    UITouch *touch =[touches anyObject];
    CGPoint currentTouchPosition = [touch locationInView:_tableView];
    NSIndexPath *indexPath= [_tableView indexPathForRowAtPoint:currentTouchPosition];
    if (indexPath.row < [_dataArrayTwo count]) {
        _pid = [_dataArrayTwo[indexPath.row] objectForKey:@"productid"];
    }
    
    NSString *kUrl;
    NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
    NSMutableArray *arr = [NSMutableArray array];//产品信息
    [arr addObject:_pid];
    [dictionary setValue:arr forKey:@"productids"];
    NSLog(@"%@",dictionary);
    NSError *error = nil;
    //NSJSONWritingPrettyPrinted:指定生成的JSON数据应使用空格旨在使输出更加可读。如果这个选项是没有设置,最紧凑的可能生成JSON表示。
    NSData *jsonData = [NSJSONSerialization
                        dataWithJSONObject:dictionary options:NSJSONWritingPrettyPrinted error:&error];
    if ([jsonData length] > 0 && error == nil){
        NSLog(@"Successfully serialized the dictionary into data.");
        //NSData转换为String
        NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
        NSLog(@"JSON String = %@", jsonString);
    }
    else if ([jsonData length] == 0 &&
             error == nil){
        NSLog(@"No data was returned after serialization.");
    }
    else if (error != nil){
        NSLog(@"An error happened = %@", error);
    }
    //post请求
    kUrl = [NSString stringWithFormat:isRecommend,[AppData share].username,[AppData share].username];
    NSMutableDictionary *dicc = [NSMutableDictionary dictionary];
    [dicc setObject:dictionary forKey:@"data"];
    // 手机型号
    NSUserDefaults *userDefaul = [NSUserDefaults standardUserDefaults];
    NSString *iptype = [userDefaul objectForKey:@"iptype"];
    NSString *banben = [userDefaul objectForKey:@"banben"];
    NSString *temUrl = [NSString stringWithFormat:@"%@&terminal=%@&OSVersion=%@",kUrl,iptype,banben];
    // 判断是否签名
    if([temUrl rangeOfString:@"sign2"].location !=NSNotFound)//_roaldSearchText
    { // 存在
    }else{ // 不存在
        temUrl = [NSString stringWithFormat:@"%@&sign2=%@",temUrl,[Utils md5SignStr]];
    }
    NSString *lower = [temUrl lowercaseString];
    if ([lower rangeOfString:@"username"].location !=NSNotFound) { // 存在
    }else{ // 不存在
        temUrl = [NSString stringWithFormat:@"%@&Username=%@",temUrl,[AppData share].username];
    }
    //NSLog(@"1----------%@",temUrl);
    temUrl = [temUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    //NSLog(@"2----------%@",temUrl);
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    NSError *error1;
    LCLog(@"%@",error1);
    NSURLResponse *theResponse;
    NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:temUrl]];
    NSString *bodyString=[NSString stringWithFormat:@"data=%@",jsonString];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setHTTPBody:[bodyString dataUsingEncoding:NSUTF8StringEncoding]];
    [theRequest addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    NSData *data = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&theResponse error:&error];
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    if ([dic[@"r"] isEqualToString:@"T"]) {
        [[MessShowView share]showWithMess:@"添加成功"];
        _cid = @"";
        
    }else {
        [[MessShowView share]showWithMess:dic[@"m"]];
    }
//    [self addProductViewWithIndexPath:indexPath];
}
- (void)endEdit {
    [_backEditView endEditing:YES];
    [_editView endEditing:YES];
}
#pragma mark --editView
- (void)createEditView {
    //背景视图
    _backEditView = [[UIView alloc]initWithFrame:CGRectMake(0, 64, ScreenWidth, ScreenHeight - 64)];
    _backEditView.tag = 888;
    _backEditView.backgroundColor = SetColor(0, 0, 0, 0.3);
    _backEditView.hidden = YES;
    UITapGestureRecognizer *tapG = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(endEdit)];
    [_backEditView addGestureRecognizer:tapG];
    [[UIApplication sharedApplication].keyWindow addSubview:_backEditView];
    //编辑视图
    _editView = [[UIView alloc]initWithFrame:CGRectMake(0, ScreenHeight - 64, ScreenWidth, 270)];
    _editView.backgroundColor = [UIColor whiteColor];
    [_backEditView addSubview:_editView];
    NSArray *titleArr = @[@"",@"商品分类",@"售价",@"成本",@"库存"];
    for (int i = 0; i < 5; i++) {
        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 44 * i, ScreenWidth, 0.5)];
        lineView.backgroundColor = SetColor(0, 0, 0, 0.2);
        [_editView addSubview:lineView];
        
        UILabel *titleLabel = [[UILabel alloc]init];
        titleLabel.font = [UIFont systemFontOfSize:14];
        titleLabel.tag = 300 + i;
        if (i == 0) {
            titleLabel.frame = CGRectMake(10, 44 * i, ScreenWidth - 20, 44);
        }else {
            titleLabel.frame = CGRectMake(10, 44 * i, 70, 44);
        }
        if (i == 0) {
//            titleLabel.text = [_dataArrayTwo[indexPpath.row]objectForKey:@"productname"];
        }else {
            titleLabel.textColor = SetColor(153, 153, 153, 1);
            titleLabel.text = titleArr[i];
        }
        if (i == 1) {
            _chooseCateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            _chooseCateBtn.frame = CGRectMake(ScreenWidth - 90, 44 * i, 70, 44);
            [_chooseCateBtn setTitle:@"选择分类" forState:UIControlStateNormal];
            [_chooseCateBtn setTitleColor:SetColor(153, 153, 153, 1) forState:UIControlStateNormal];
            _chooseCateBtn.titleLabel.font = [UIFont systemFontOfSize:14];
            [_chooseCateBtn addTarget:self action:@selector(chooseTheCategory) forControlEvents:UIControlEventTouchUpInside];
            [_editView addSubview:_chooseCateBtn];
            
            _cnameLabel = [[UILabel alloc]initWithFrame:CGRectMake(90, 44, 70, 44)];
            _cnameLabel.font = [UIFont systemFontOfSize:14];
            
            [_editView addSubview:_cnameLabel];
            UIImageView *inImageV = [[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth - 15, 44 + 15, 7, 13)];
            inImageV.image = [UIImage imageNamed:@"inImagePic"];
            [_editView addSubview:inImageV];
            
        }
        if (i == 2 || i == 3 || i == 4) {
            UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(52, 44 * i + 7, 250, 30)];
            textField.textColor = SetColor(153, 153, 153, 1);
            textField.delegate = self;
            [textField addTarget:self action:@selector(textfieldChange:) forControlEvents:UIControlEventEditingChanged];
            textField.keyboardType = UIKeyboardTypeDecimalPad;
            textField.tag = 70+i;//72,73,74
            textField.font = [UIFont systemFontOfSize:14];
            [_editView addSubview:textField];
        }
        [_editView addSubview:titleLabel];
    }
    NSArray *arr = @[@"保存",@"取消"];
    for (int i = 0; i < 2; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(ScreenWidth/2 * i, 220, ScreenWidth/2, 50);
        if (i == 0) {
            btn.backgroundColor = MainColorT;
        }else {
            btn.backgroundColor = MainColorOld;
        }
        btn.tag = 60 + i;
        [btn addTarget:self action:@selector(CancelOrDoneBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [btn setTitle:arr[i] forState:UIControlStateNormal];
        [_editView addSubview:btn];
    }
}
#pragma mark -- 编辑视图....
- (void)addProductViewWithIndexPath:(NSIndexPath *)indexPpath {
//    //背景视图
    UILabel *TTlable = (UILabel *)[_backEditView viewWithTag:300];
    UITextField *shouJiaTextF = (UITextField *)[_backEditView viewWithTag:72];
    UITextField *chengbenTextF = (UITextField *)[_backEditView viewWithTag:73];
    UITextField *kuncunTextF = (UITextField *)[_backEditView viewWithTag:74];
    if (indexPpath.row < [_dataArrayTwo count]) {
        TTlable.text = [_dataArrayTwo[indexPpath.row]objectForKey:@"productname"];
        _shoujiaStr = [_dataArrayTwo[indexPpath.row]objectForKey:@"price"];
        shouJiaTextF.text = _shoujiaStr;
        
        _chengbenStr = [_dataArrayTwo[indexPpath.row] objectForKey:@"price"];
        chengbenTextF.text = _chengbenStr;
        
        _kucunStr = [_dataArrayTwo[indexPpath.row] objectForKey:@"dftstock"];
        kuncunTextF.text = _kucunStr;
    }
    [_chooseCateBtn setTitle:@"选择分类" forState:UIControlStateNormal];
    _chooseCateBtn.frame = CGRectMake(ScreenWidth - 90, 44, 70, 44);
    _cid = @"";
    _backEditView.hidden = NO;
    
    [self EditViewComeBack];
}
#pragma mark == 编辑视图的保存和取消...
- (void)CancelOrDoneBtnClick:(UIButton *)sender {
    if (sender.tag == 60) {
        if ([_cid isEqualToString:@""]) {
            [[MessShowView share]showWithMess:@"未选择商品分类"];
            return;
        }
        if ([_shoujiaStr isEqualToString:@""] || [_chengbenStr isEqualToString:@""] || [_kucunStr isEqualToString:@""]) {
            [[MessShowView share]showWithMess:@"商品信息不能为空"];
            return;
        }
        NSString *kUrl;
        NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
        [dictionary setValue:[AppData share].username forKey:@"productuser"];
        [dictionary setValue:_cid forKey:@"catetypeid"];
        NSMutableDictionary *arrDic = [[NSMutableDictionary alloc]init];
        NSLog(@"%@",_pid);
        [arrDic setValue:_pid forKey:@"prodid"];
        [arrDic setValue:_shoujiaStr forKey:@"price"];
        [arrDic setValue:_chengbenStr forKey:@"costprice"];
        [arrDic setValue:_kucunStr forKey:@"stock"];
        NSMutableArray *arr = [NSMutableArray array];
        [arr addObject:arrDic];
        [dictionary setValue:arr forKey:@"prodinfo"];
        NSError *error = nil;
        //NSJSONWritingPrettyPrinted:指定生成的JSON数据应使用空格旨在使输出更加可读。如果这个选项是没有设置,最紧凑的可能生成JSON表示。
        NSData *jsonData = [NSJSONSerialization
                            dataWithJSONObject:dictionary options:NSJSONWritingPrettyPrinted error:&error];
        if ([jsonData length] > 0 && error == nil){
            NSLog(@"Successfully serialized the dictionary into data.");
            //NSData转换为String
            NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
            NSLog(@"JSON String = %@", jsonString);
        }
        else if ([jsonData length] == 0 &&
                 error == nil){
            NSLog(@"No data was returned after serialization.");
        }
        else if (error != nil){ 
            NSLog(@"An error happened = %@", error); 
        }
        //post请求
        kUrl = [NSString stringWithFormat:ChangeProductDataUrl];
        NSLog(@"%@",kUrl);
        NSMutableDictionary *dicc = [NSMutableDictionary dictionary];
        [dicc setObject:dictionary forKey:@"data"];
        NSLog(@"%@",dicc);
        // 手机型号
        NSUserDefaults *userDefaul = [NSUserDefaults standardUserDefaults];
        NSString *iptype = [userDefaul objectForKey:@"iptype"];
        NSString *banben = [userDefaul objectForKey:@"banben"];
        NSString *temUrl = [NSString stringWithFormat:@"%@&terminal=%@&OSVersion=%@",kUrl,iptype,banben];
        // 判断是否签名
        if([temUrl rangeOfString:@"sign2"].location !=NSNotFound)//_roaldSearchText
        {
            // 存在
        }else{
            // 不存在
            temUrl = [NSString stringWithFormat:@"%@&sign2=%@",temUrl,[Utils md5SignStr]];
        }
        NSString *lower = [temUrl lowercaseString];
        if ([lower rangeOfString:@"username"].location !=NSNotFound) {
            // 存在
        }else{
            // 不存在
            temUrl = [NSString stringWithFormat:@"%@&Username=%@",temUrl,[AppData share].username];
        }
        NSLog(@"1----------%@",temUrl);
        temUrl = [temUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSLog(@"2----------%@",temUrl);
        NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
        NSError *error1;
        NSURLResponse *theResponse;
        NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:temUrl]];
        
        NSString *bodyString=[NSString stringWithFormat:@"data=%@",jsonString];
        NSLog(@"%@",bodyString);
        [theRequest setHTTPMethod:@"POST"];
        [theRequest setHTTPBody:[bodyString dataUsingEncoding:NSUTF8StringEncoding]];
        [theRequest addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
        NSData *data = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&theResponse error:&error];
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",dic[@"r"]);
        if ([dic[@"r"] isEqualToString:@"T"]) {
            [[MessShowView share]showWithMess:@"添加成功"];
            [self endEdit];
            [self EditViewGoOut];
            _backEditView.hidden = YES;
            _cid = @"";
        }else {
            [[MessShowView share]showWithMess:dic[@"m"]];
        }
    }else if (sender.tag == 61){//取消
        _cid = @"";
//        [self EditViewGoOut];
        [_backEditView endEditing:YES];
        [_editView endEditing:YES];
        [UIView animateWithDuration:0.3 animations:^{
            _editView.frame = CGRectMake(0, ScreenHeight - 64, ScreenWidth, 270);
        } completion:^(BOOL finished) {
            _backEditView.hidden = YES;
        }];
    }
}
#pragma mark -- 编辑视图移除屏幕
- (void)EditViewGoOut {
    [UIView animateWithDuration:0.3 animations:^{
        _editView.frame = CGRectMake(0, ScreenHeight - 64, ScreenWidth, 270);
    }];
}
#pragma mark -- 编辑视图回到屏幕
- (void)EditViewComeBack {
    [UIView animateWithDuration:0.3 animations:^{
        _editView.frame = CGRectMake(0, ScreenHeight - 64 - 270, ScreenWidth, 270);
    }];
}
#pragma mark -- 选择分类
- (void)chooseTheCategory {
    NSLog(@"888");
     classifyViewController *classman = [[classifyViewController alloc] init];
    classman.categorySelectedBlock = ^(NSString *categoryStr,NSString *categoryId){
        _cname = categoryStr;
        _cid = categoryId;
        _IsHidden = YES;
        CGSize size = [categoryStr sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:_chooseCateBtn.titleLabel.font,NSFontAttributeName, nil]];
        _chooseCateBtn.frame = CGRectMake(ScreenWidth - 20 - size.width, _chooseCateBtn.frame.origin.y, size.width, 44);
        [_chooseCateBtn setTitle:categoryStr forState:UIControlStateNormal];
        
    };
    if (_myBlock) {
        _myBlock(classman);
    }else {
        [self.navigationController pushViewController:classman animated:YES];
    }
    _backEditView.hidden = YES;
}
#pragma mark--tableviewdelegate的协议方法
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleNone;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataArrayTwo.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ProductLibTableviewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"productlibcell"];
    if (cell == nil) {
        cell = [[NSBundle mainBundle]loadNibNamed:@"ProductLibTableviewCell" owner:nil options:nil][0];
    }
    if ([_isShowSearch isEqualToString:@"YES"]) {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }else {
        cell.selectionStyle = UITableViewCellSelectionStyleDefault;
        cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
        cell.selectedBackgroundView.backgroundColor = [UIColor whiteColor];
    }
    [cell.addBtn addTarget:self action:@selector(addProductBtnClick:event:) forControlEvents:UIControlEventTouchUpInside];
    
    if (indexPath.row < [_dataArrayTwo count]) {
        [cell.iconImageView sd_setImageWithURL:[NSURL URLWithString:[_dataArrayTwo[indexPath.row] objectForKey:@"mainimage"]] placeholderImage:[UIImage imageNamed:@"product-no-pic"]];
        cell.TTitleLabel.text = [_dataArrayTwo[indexPath.row] objectForKey:@"productname"];
        cell.descLabel.text = [_dataArrayTwo[indexPath.row] objectForKey:@"specname"];
        cell.salePriceLabel.text = [_dataArrayTwo[indexPath.row] objectForKey:@"minsaleprice"];
    }
    //
    if (indexPath.row < [_m_fileItems count]) {
        FileItem* fileItem = [_m_fileItems objectAtIndex:indexPath.row];
        [cell setChecked:fileItem.checked];
    }
    if (_tableView.editing) {
        cell.addBtn.hidden = YES;
    }else {
        cell.addBtn.hidden = NO;
    }
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 90;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.0001;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.0001;
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)])
    {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)])
    {
        [cell setPreservesSuperviewLayoutMargins:NO];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)])
    {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    FileItem* fileItem;
    if (indexPath.row < [_m_fileItems count]) {
        fileItem = [_m_fileItems objectAtIndex:indexPath.row];
    }
    if (self.editing)
    {
        ProductLibTableviewCell *cell = (ProductLibTableviewCell*)[_tableView cellForRowAtIndexPath:indexPath];
        fileItem.checked = !fileItem.checked;
        [cell setChecked:fileItem.checked];
        if (fileItem.checked) {
            [_selectedArr replaceObjectAtIndex:indexPath.row withObject:@{@"a":@"1"}];
        }else {
            [_selectedArr replaceObjectAtIndex:indexPath.row withObject:_dataArrayTwo[indexPath.row]];
        }
        NSLog(@"=66=%@",_selectedArr);
        
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
    }
    
    [self refreshAddBtnState];
    
}
- (void) setEditing:(BOOL)editting animated:(BOOL)animated {
    [super setEditing:editting animated:animated];
    if (!editting)
    {
        for (FileItem* item in _m_fileItems)
        {
            item.checked = NO;
        }
    }
}
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return YES;
}
#pragma mark -- 词频所有词变更判断
- (void)textfieldChange:(UITextField *)textField {
    NSLog(@"1234567890-");
    if (textField.tag == 72) {
        if ([self validateNumber:textField.text]) {
            _shoujiaStr = textField.text;
        }else {
            textField.text = _shoujiaStr;
        }
    }else if (textField.tag == 73){
        if ([self validateNumber:textField.text]) {
            _chengbenStr = textField.text;
        }else {
            textField.text = _chengbenStr;
        }
    }else if (textField.tag == 74){
        if ([self validateNumber:textField.text]) {
            _kucunStr = textField.text;
        }else {
            textField.text = _kucunStr;
        }
    }
}
- (BOOL)validateNumber:(NSString*)number {
    BOOL res = YES;
    NSCharacterSet* tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789."];
    int i = 0;
    while (i < number.length) {
        NSString * string = [number substringWithRange:NSMakeRange(i, 1)];
        NSRange range = [string rangeOfCharacterFromSet:tmpSet];
        if (range.length == 0) {
            res = NO;
            break;
        }
        i++;
    }
    return res;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}
- (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    //if (textField == _textField1) {
    NSScanner      *scanner    = [NSScanner scannerWithString:string];
    NSCharacterSet *numbers;
    NSRange         pointRange = [textField.text rangeOfString:@"."];
    
    if ( (pointRange.length > 0) && (pointRange.location < range.location  || pointRange.location > range.location + range.length) )
    {
        numbers = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
    }
    else
    {
        //        if (textField == _textField1) {
        //            numbers = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
        //        }else {
        numbers = [NSCharacterSet characterSetWithCharactersInString:@"0123456789."];
        //        }
    }
    
    if ( [textField.text isEqualToString:@""] && [string isEqualToString:@"."] )
    {
        return NO;
    }
    
    short remain = 2; //默认保留2位小数
    
    NSString *tempStr = [textField.text stringByAppendingString:string];
    NSUInteger strlen = [tempStr length];
    if(pointRange.length > 0 && pointRange.location > 0){ //判断输入框内是否含有“.”。
        if([string isEqualToString:@"."]){ //当输入框内已经含有“.”时，如果再输入“.”则被视为无效。
            return NO;
        }
        if(strlen > 0 && (strlen - pointRange.location) > remain+1){ //当输入框内已经含有“.”，当字符串长度减去小数点前面的字符串长度大于需要要保留的小数点位数，则视当次输入无效。
            return NO;
        }
    }
    NSRange zeroRange = [textField.text rangeOfString:@"0"];
    if(zeroRange.length == 1 && zeroRange.location == 0){ //判断输入框第一个字符是否为“0”
        if(![string isEqualToString:@"0"] && ![string isEqualToString:@"."] && [textField.text length] == 1){ //当输入框只有一个字符并且字符为“0”时，再输入不为“0”或者“.”的字符时，则将此输入替换输入框的这唯一字符。
            textField.text = string;
            return NO;
        }else{
            if(pointRange.length == 0 && pointRange.location > 0){ //当输入框第一个字符为“0”时，并且没有“.”字符时，如果当此输入的字符为“0”，则视当此输入无效。
                if([string isEqualToString:@"0"]){
                    return NO;
                }
            }
        }
    }
    NSString *buffer;
    if ( ![scanner scanCharactersFromSet:numbers intoString:&buffer] && ([string length] != 0) )
    {
        return NO;
    }
    //}
    return YES;
}

#pragma mark -- 刷新一键导入按钮状态
- (void)refreshAddBtnState
{
    NSInteger seleCount = _selectedArr.count;
    for (NSInteger i = _selectedArr.count - 1; i >= 0; i--) {
        NSDictionary *dic = (NSDictionary *)_selectedArr[i];
        if ([[dic allKeys] containsObject:@"a"]) {
            seleCount--;
        }
    }
    BOOL isAllSele = NO;
    if (seleCount == _selectedArr.count)
    {
        isAllSele = YES;
    }
    NSLog(@"seleCount = %ld",seleCount);
    if (self.refreshAddBtnStateBlock) {
        self.refreshAddBtnStateBlock(seleCount,isAllSele);
    }
}


- (void)viewWillDisappear:(BOOL)animated {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"all_selected_BTN" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"ClassifyBack" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"CategoryNotiF" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidChangeFrameNotification object:nil];
    [_backEditView endEditing:YES];
    _backEditView.hidden = YES;
    [self EditViewGoOut];
}
@end